﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
namespace Andrewl.XnaHelpers.Input
{
    public class Input_Mouse
    {
        #region Variable Declarations

        public MouseState previousMouseState;

        public MouseState currentMouseState;

        #endregion

        public Input_Mouse()
        { }

        public void Update()
        {
            previousMouseState = currentMouseState;
            currentMouseState = Mouse.GetState();
        }

        #region Accessors

        public MouseState PreviousMouseState
        { get { return previousMouseState; } }

        public MouseState CurrentMouseState
        { get { return currentMouseState; } }

        public Vector2 PositionFloat
        {
            get { return new Vector2(currentMouseState.X, currentMouseState.Y); } 
        }
        
        public Point PositionInt
        {
            get { return new Point(currentMouseState.X, currentMouseState.Y); }
        }

        public int X
        { 
            get { return currentMouseState.X; } 
        }

        public int Y
        { 
            get { return currentMouseState.Y; } 
        }

        public int ScrollWheel
        { 
            get { return currentMouseState.ScrollWheelValue; } 
        }

        #endregion

        #region Functions

        public bool LeftMouseButtonDown()
        {
            if (currentMouseState.LeftButton == ButtonState.Pressed)
                return true;
            else
                return false;
        }

        public bool LeftMouseButtonPressed()
        {
            if (currentMouseState.LeftButton == ButtonState.Pressed && previousMouseState.LeftButton == ButtonState.Released)
                return true;
            else
                return false;
        }

        public bool RightMouseButtonDown()
        {
            if (currentMouseState.RightButton == ButtonState.Pressed)
                return true;
            else
                return false;
        }

        public bool RightMouseButtonPressed()
        {
            if (currentMouseState.RightButton == ButtonState.Pressed && previousMouseState.MiddleButton == ButtonState.Released)
                return true;
            else
                return false;
        }

        public bool MiddleMouseButtonDown()
        {
            if (currentMouseState.MiddleButton == ButtonState.Pressed)
                return true;
            else
                return false;
        }

        public bool MiddleMouseButtonPressed()
        {
            if (currentMouseState.MiddleButton == ButtonState.Pressed && previousMouseState.MiddleButton == ButtonState.Released)
                return true;
            else
                return false;
        }

        public bool X1ButtonDown()
        {
            if (currentMouseState.XButton1 == ButtonState.Pressed)
                return true;
            else
                return false;
        }

        public bool X1ButtonPressed()
        {
            if (currentMouseState.XButton1 == ButtonState.Pressed && previousMouseState.XButton1 == ButtonState.Released)
                return true;
            else
                return false;
        }

        public bool X2ButtonDown()
        {
            if (currentMouseState.XButton2 == ButtonState.Pressed)
                return true;
            else
                return false;
        }

        public bool X2ButtonPressed()
        {
            if (currentMouseState.XButton2 == ButtonState.Pressed && previousMouseState.XButton2 == ButtonState.Released)
                return true;
            else
                return false;
        }

        #endregion
    }
}
